import axios from "axios";
import {accessToken, instanceUrl } from "./constants";

const getShortcutByName = async (name: string) => {
  const normalizedUrl = instanceUrl.replace(/\/+$/, "");
  try {
    const resp = await axios.get(`${normalizedUrl}/api/v1/shortcuts/name/${name}`, {
      headers: {
        Authorization: `Bearer ${accessToken}`,
      },
    })
    return resp.data;
  } catch (error){
    if (error.status === 404) {
      return null;
    } else {
      throw error;
    }
  }
}

export default getShortcutByName;
